import { getInfo as memberInfo} from '../../../../api/shareCenter'
import { getInfo as enterpriseInfo} from '../../../../api/enterprise'
const util = require('../../../../utils/util.js')

const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    memberInfo: {point:"0"},
    enterpriseInfoObj:{}
  },

  loadPromoter() {
    memberInfo().then(res => {
      this.data.memberInfo = res.data
      let point = this.data.memberInfo.point/100;
      this.data.memberInfo.point =  point.toFixed(2);
      let freezePoint = this.data.memberInfo.freezePoint/100;
      this.data.memberInfo.canUsePoint = point-freezePoint;
      this.data.memberInfo.canUsePoint = this.data.memberInfo.canUsePoint.toFixed(2);
      this.data.memberInfo.freezePoint =  freezePoint.toFixed(2);
      this.data.memberInfo.stockRight =  res.data.member.stockRight.toFixed(2);
      if(this.data.memberInfo.stockRight == "" || this.data.memberInfo.stockRight == null ){
        this.data.memberInfo.stockRight = 0
      }
      this.setData({
        memberInfo: this.data.memberInfo
      })
    })
  },
  toStockRight() {
    wx.navigateTo({
      url: '/pages/wallet/jumpPage/stockRight/stockRight'
    })
  },
  toTransfer() {
    if (this.data.memberInfo.point==0) {
      wx.showToast({
        title: '可提现余额不能为0',
        icon:"none"
      })
      return;
    }
    wx.navigateTo({
      url: '/pages/wallet/jumpPage/distribution/transfer'
    })
  },
  getEnterpriseInfo(){
    const that = this;
    enterpriseInfo().then((res)=>{
      that.setData({
        enterpriseInfoObj: res.data
      })
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

    this.data.canvasH = (wx.getSystemInfoSync().windowWidth / 750).toFixed(2)
    this.data.canvasHeight = 500 * this.data.canvasH

  },

  /**z
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this.loadPromoter();
    this.getEnterpriseInfo()
    },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  toDistribution(){
    wx.navigateTo({
      url: '/pages/wallet/jumpPage/distribution/distribution',
    })
  },
  toBestow(e){
    wx.navigateTo({
      url:'/pages/wallet/jumpPage/distribution/bestow?point='+ this.data.memberInfo.canUsePoint,
    })
  }

})
